'    Copyright 2008 Jan Molnar <jan.molnar@abds.de>
'
'    This file is part of JCQ.

'    JCQ is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 2 of the License, or
'    (at your option) any later version.

'    JCQ is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.

'    You should have received a copy of the GNU General Public License
'    along with JCQ. If not, see <http://www.gnu.org/licenses/>.

Imports System.Windows
Imports System.Windows.Interop

''' <summary>
''' Extends a Wpf Window to support manual resizing.
''' </summary>
''' <remarks>To use this functionality your application needs FullTrust privileges.</remarks>
Public Class WindowResizeExtender
    Private WithEvents _Window As Window

    Friend Sub New()

    End Sub

    ''' <summary>
    ''' Gets or sets the window object to extend.
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Window() As Window
        Get
            Return _Window
        End Get
        Set(ByVal value As Window)
            _Window = value
            _Window.WindowStyle = WindowStyle.None
            _Window.ResizeMode = ResizeMode.NoResize
        End Set
    End Property

    ''' <summary>
    ''' Allows the window to be resized.
    ''' </summary>
    ''' <param name="sizingAction"></param>
    ''' <remarks></remarks>
    Public Sub DragSize(ByVal sizingAction As SizingAction)
        If System.Windows.Input.Mouse.LeftButton = Input.MouseButtonState.Pressed Then
            Win32Methods.SendMessage(_Handle, WindowMessage.WM_SYSCOMMAND, New IntPtr(SysCommand.SC_SIZE + sizingAction), IntPtr.Zero)
            Win32Methods.SendMessage(_Handle, 514, IntPtr.Zero, IntPtr.Zero)
        End If
    End Sub
End Class

''' <summary>
''' Maps Win32 Sizing Actions
''' </summary>
''' <remarks></remarks>
Public Enum SizingAction
    North = 3
    South = 6
    East = 2
    West = 1
    NorthEast = 5
    NorthWest = 4
    SouthEast = 8
    SouthWest = 7
End Enum